package com.muyu.product.domain.resp;

import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.product.domain.AttributeGroup;
import com.muyu.product.domain.AttributeInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.List;
import java.util.function.Function;

/**
 * @author DongZl
 * @description: 属性组列表对象
 * @Date 2024-2-28 下午 04:15
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class AttributeGroupPageResp extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /** 属性组编号 */
    private Long id;

    /** 组名称 */
    private String name;

    /** 状态 */
    private String states;

    /**
     * 属性对象集合
     */
    private List<AttributeInfo> attributeInfoList;

    public static AttributeGroupPageResp groupBuild (AttributeGroup attributeGroup, List<AttributeInfo> attributeInfos) {
        return AttributeGroupPageResp.builder()
                .id(attributeGroup.getId())
                .name(attributeGroup.getName())
                .states(attributeGroup.getStates())
                .attributeInfoList(attributeInfos)
                .build();
    }
    public static AttributeGroupPageResp groupFunBuild (AttributeGroup attributeGroup, Function<Long,List<AttributeInfo> > function) {
        return AttributeGroupPageResp.builder()
                .id(attributeGroup.getId())
                .name(attributeGroup.getName())
                .states(attributeGroup.getStates())
                .attributeInfoList(function.apply(attributeGroup.getId()))
                .build();
    }
}
